﻿using BLL;
using InventoryMIS2019.conn;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace InventoryMIS2019
{
    public partial class _ExaminPurchaseBill : InventoryMIS2019.Templates.BasePurchaseBillForm
    {
        List<string> pendingIDList;//待审核订单列表泛型集合
        ExaminPurchaseBillBLL bl; //审核页面业务逻辑类
        string opera;
        public _ExaminPurchaseBill()
        {
            InitializeComponent();
            bl = new ExaminPurchaseBillBLL();
            lbPurchaseBill.Enabled = true;
        }
        /// <summary>
        /// 获取待审核订单列表
        /// </summary>
        /// <returns></returns>
        private List <string > GetPendingPurchaseBill()
        {
            pendingIDList = bl.GetPendingPurchaseBill();
            return pendingIDList;
        }

        private void lbPurchaseBill_VisibleChanged(object sender, EventArgs e)
        {
            if (GetPendingPurchaseBill().Count ==0)
            {
                lbPurchaseBill.DataSource = null;
            }
            else
            {
                lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                lbPurchaseBill.SelectedIndex = -1;
            }
        }
        /// <summary>
        /// 获取控件值
        /// </summary>
        private void GetValues()
        {
            bo = new PurchaseBill(); 
            bo.PurchaseBillID = txtPurchaseID.Text.Trim();
            bo.Examiner = "800001";
            bo.Memo = txtMemo.Text;
        }

        private void bntAuditYes_Click(object sender, EventArgs e)
        {
            GetValues();
            opera = "YES";
        }

        private void bntAuditNO_Click(object sender, EventArgs e)
        {
            GetValues();
            opera = "NO";
        }

        private void bntYes_Click(object sender, EventArgs e)
        {
            if (opera =="YES")
            {
                if (bl .PassExamine (bo ))
                {
                    MessageBox.Show("订单审核通过", "系统提示");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill( );
                }
            }
            if (opera =="NO")
            {
                if (bl.NOPassExamine(bo))
                {
                    MessageBox.Show("订单审核不通过", "系统提示");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                }
                bntAuditYes.Enabled = bntAuditNO.Enabled = true;
            }
        }

        private void bntUndo_Click(object sender, EventArgs e)
        {
            bntAuditYes.Enabled = bntAuditNO.Enabled = true;
            ClearControls.ClearControl(this);
            lbPurchaseBill.DataSource = GetPendingPurchaseBill();//更新ListBox控件数据源
        }
    }
}
